package Demo;

import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.border.LineBorder;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.ImageObserver;
import java.io.File;
import java.text.AttributedCharacterIterator;

public class Demo91 {

    public static void main(String[] args) throws Exception {
        ImageIcon icon = new ImageIcon(ImageIO.read(new File("D:\\test\\images\\4.png")));
        JFrame jf = new JFrame();
        jf.setBounds(200, 200, 500, 500);
        jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        jf.setBackground(Color.WHITE);
        menu pane = new menu("background-3");
        jf.setContentPane(pane);
        pane.setBackground(Color.WHITE);
        pane.setLayout(new BorderLayout());
        JPanel jmain = new JPanel();
        jmain.setBackground(Color.WHITE);
        //*********************************
        JPanel jdown= new JPanel();
        menu d1 = new menu("background-1");
        menu d2 = new menu("background-2");
        menu d3 = new menu("background-3");
        jdown.add(d1,"1");
        jdown.add(d2,"2");
        jdown.add(d3,"3");
        //*********************************
        JToolBar jt = new JToolBar();
        jt.setBorder(new LineBorder(Color.WHITE));
        JButton jButton = new JButton(icon);
        jButton.setBackground(Color.WHITE);
        jt.add(jButton);
        //***********************************************
        JMenuBar jb = new JMenuBar();
        jb.setBorderPainted(false);
        jb.setBackground(Color.WHITE);
        JMenu file = new JMenu("File");
        JMenuItem New = new JMenuItem("New");
        JMenuItem open = new JMenuItem("Open");
        JMenuItem setting = new JMenuItem("Setting");
        file.add(New);
        file.add(open);
        file.add(setting);
        JMenu edit = new JMenu("Edit");
        JMenuItem cut = new JMenuItem("Cut");
        JMenuItem copy = new JMenuItem("Copy");
        JMenuItem delete = new JMenuItem("Delete");
        edit.add(cut);
        edit.add(copy);
        edit.add(delete);
        JMenu navigate = new JMenu("Navigate");
        jb.add(file);
        jb.add(edit);
        jb.add(navigate);
        jb.add(Box.createHorizontalGlue());
        //*********************************************
        jmain.setLayout(new FlowLayout(FlowLayout.LEFT));
        jmain.add(jt);
        jmain.add(jb);
        //*********************************************
        pane.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseReleased(MouseEvent e) {
                CardLayout cardLayout=new CardLayout();
                if (e.isMetaDown()) {
                    JPopupMenu jp = new JPopupMenu();
                    JMenuItem j1 = new JMenuItem("background-1");
                    j1.addActionListener((event) -> {
                      j1.add(new menu("background-1"));
                    });
                    JMenuItem j2 = new JMenuItem("background-2");
                    j2.addActionListener((event) -> {
                        j2.add(new menu("background-2"));

                    });
                    JMenuItem j3 = new JMenuItem("background-3");
                    j3.addActionListener((event) -> {
                        j3.add(new menu("background-3"));
                    });
                    jp.add(j1);
                    jp.add(j2);
                    jp.add(j3);
                    jp.show(e.getComponent(), e.getX(), e.getY());
                }
            }
        });
        //*********************************************

        pane.add(jmain, BorderLayout.NORTH);
        jf.setVisible(true);
    }
}

class menu extends JPanel {
    String name;

    public menu(String name) {
        this.name = name;
    }

    @Override
    protected void paintComponent(Graphics g) {
        try {
            Image image1 = ImageIO.read(new File("D:\\test\\images\\1.jpg"));
            Image image2 = ImageIO.read(new File("D:\\test\\images\\2.jpg"));
            Image image3 = ImageIO.read(new File("D:\\test\\images\\3.jpg"));
            if (name.equals("background-1")) {
                g.drawImage(image1, 0, 0, null);
            }
            if (name.equals("background-2")) {
                g.drawImage(image2, 0, 0, null);
            }
            if (name.equals("background-3")) {
                g.drawImage(image3, 0, 0, this.getWidth(), this.getHeight(), null);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}

class paint extends Graphics {

    protected paint() {

    }

    @Override
    public Graphics create(int x, int y, int width, int height) {
        return null;
    }

    @Override
    public FontMetrics getFontMetrics() {
        return null;
    }

    @Override
    public void drawRect(int x, int y, int width, int height) {

    }

    @Override
    public void draw3DRect(int x, int y, int width, int height, boolean raised) {

    }

    @Override
    public void fill3DRect(int x, int y, int width, int height, boolean raised) {

    }

    @Override
    public void drawPolygon(Polygon p) {

    }

    @Override
    public void fillPolygon(Polygon p) {

    }

    @Override
    public void drawChars(char[] data, int offset, int length, int x, int y) {

    }

    @Override
    public void drawBytes(byte[] data, int offset, int length, int x, int y) {

    }

    @Override
    public void finalize() {

    }

    @Override
    public String toString() {
        return null;
    }

    @Override
    public Rectangle getClipRect() {
        return null;
    }

    @Override
    public boolean hitClip(int x, int y, int width, int height) {
        return false;
    }

    @Override
    public Rectangle getClipBounds(Rectangle r) {
        return null;
    }

    @Override
    public Graphics create() {
        return null;
    }

    @Override
    public void translate(int i, int i1) {

    }

    @Override
    public Color getColor() {
        return null;
    }

    @Override
    public void setColor(Color color) {

    }

    @Override
    public void setPaintMode() {

    }

    @Override
    public void setXORMode(Color color) {

    }

    @Override
    public Font getFont() {
        return null;
    }

    @Override
    public void setFont(Font font) {

    }

    @Override
    public FontMetrics getFontMetrics(Font font) {
        return null;
    }

    @Override
    public Rectangle getClipBounds() {
        return null;
    }

    @Override
    public void clipRect(int i, int i1, int i2, int i3) {

    }

    @Override
    public void setClip(int i, int i1, int i2, int i3) {

    }

    @Override
    public Shape getClip() {
        return null;
    }

    @Override
    public void setClip(Shape shape) {

    }

    @Override
    public void copyArea(int i, int i1, int i2, int i3, int i4, int i5) {

    }

    @Override
    public void drawLine(int i, int i1, int i2, int i3) {

    }

    @Override
    public void fillRect(int i, int i1, int i2, int i3) {

    }

    @Override
    public void clearRect(int i, int i1, int i2, int i3) {

    }

    @Override
    public void drawRoundRect(int i, int i1, int i2, int i3, int i4, int i5) {

    }

    @Override
    public void fillRoundRect(int i, int i1, int i2, int i3, int i4, int i5) {

    }

    @Override
    public void drawOval(int i, int i1, int i2, int i3) {

    }

    @Override
    public void fillOval(int i, int i1, int i2, int i3) {

    }

    @Override
    public void drawArc(int i, int i1, int i2, int i3, int i4, int i5) {

    }

    @Override
    public void fillArc(int i, int i1, int i2, int i3, int i4, int i5) {

    }

    @Override
    public void drawPolyline(int[] ints, int[] ints1, int i) {

    }

    @Override
    public void drawPolygon(int[] ints, int[] ints1, int i) {

    }

    @Override
    public void fillPolygon(int[] ints, int[] ints1, int i) {

    }

    @Override
    public void drawString(String s, int i, int i1) {

    }

    @Override
    public void drawString(AttributedCharacterIterator attributedCharacterIterator, int i, int i1) {

    }

    @Override
    public boolean drawImage(Image image, int i, int i1, ImageObserver imageObserver) {
        return false;
    }

    @Override
    public boolean drawImage(Image image, int i, int i1, int i2, int i3, ImageObserver imageObserver) {
        return false;
    }

    @Override
    public boolean drawImage(Image image, int i, int i1, Color color, ImageObserver imageObserver) {
        return false;
    }

    @Override
    public boolean drawImage(Image image, int i, int i1, int i2, int i3, Color color, ImageObserver imageObserver) {
        return false;
    }

    @Override
    public boolean drawImage(Image image, int i, int i1, int i2, int i3, int i4, int i5, int i6, int i7, ImageObserver imageObserver) {
        return false;
    }

    @Override
    public boolean drawImage(Image image, int i, int i1, int i2, int i3, int i4, int i5, int i6, int i7, Color color, ImageObserver imageObserver) {
        return false;
    }

    @Override
    public void dispose() {

    }
}
